game_manager
{
	spawn
	{
		// Set scenario information

		wm_axis_respawntime		30
		wm_allied_respawntime		15
		wm_set_round_timelimit		20
		wm_number_of_objectives		5

		// Objectives
		// 1: Forward Spawn
		// 2: Dynamite Detonator
		// 3: Commandpost
		// 4: Keycodes Documents
		// 5: Destroy the Big Gun

		wm_set_main_objective		5	0
		wm_set_main_objective		5	1

		wm_objective_status 1 1 0
		wm_objective_status 1 0 0
		wm_objective_status 2 1 0
		wm_objective_status 2 0 0
		wm_objective_status 3 1 0
		wm_objective_status 3 0 0
		wm_objective_status 4 1 0
		wm_objective_status 4 0 0
		wm_objective_status 5 1 0
		wm_objective_status 5 0 0

		// Stopwatch mode defending team (0=Axis, 1=Allies)
		wm_set_defending_team	0

		// If the round timer expires, no one has won
		// Set the round winner:  0 == AXIS, 1 == ALLIED
		wm_setwinner 0

		// Set start spawnpoints
		wait 500
		setautospawn "Truck Spawn" 1
		setautospawn "Town Spawn" 0

		construct gun_build
		construct town_barb
		setstate keycode_door_locked invisible
	}

	trigger gun_boom // Trigger this when the Big Gun is blown
	{
		// UI pop-up to alert players
		wm_announce	"Allies have destroyed the Big Gun!"

		wm_objective_status 5 1 2
		wm_objective_status 5 0 1

		accum 1 set 1				// End of game completed

		// Call function to check if the round has been won
		trigger game_manager checkgame
	}

	trigger checkgame // Set Winner to Allies
	{
		accum 1 abort_if_not_equal 1

		// Set the round winner:  0 == AXIS, 1 == ALLIED
		wm_setwinner 1

		// End the round
		wm_endround

		wait 4000
		
		// Play Destroyed scene
		alertentity gun_destroyed
	}

}


// ================================================
// =========== SPAWN POINT CONTROLS ===============
// ================================================
town_spawn_axis // Axis spawnpoints in town

{
	spawn
	{
		wait 200
	}

	trigger kill
	{
		remove
	}
}

town_spawn_allies // Allies spawnpoints in town

{
	spawn
	{
		wait 200
	}

	trigger kill
	{
		remove
	}
}


town_spawn_allies2 // Allies spawnpoints at town not usable until battery capped.
{
	spawn
	{
		wait 200
		setstate town_spawn_allies2 invisible
	}

	trigger invisible
	{
		wait 100
		setstate town_spawn_allies2 invisible
	}

	trigger visible
	{
		wait 100
		alertentity town_spawn_allies2
		setstate town_spawn_allies2 default
	}

	trigger kill
	{
		remove
	}
}







// ============================================
// Dynamite Detonator and Battery
// ============================================

det_bat_flag 
{
	spawn
	{
		wait 200
		setstate det_bat_flag default
	}

	trigger invisible
	{
		setstate det_bat_flag invisible
		wait 100
	}

	trigger visible
	{
		setstate det_bat_flag default
		wait 100
	}
}

det_bat_marker
{
	spawn
	{
		wait 200
		setstate det_bat_marker default
	}

	trigger invisible
	{
		setstate det_bat_marker invisible
		wait 100
	}

	trigger visible
	{
		setstate det_bat_marker default
		wait 100
	}
}

det_dropoff_marker
{
	spawn
	{
		wait 200
		setstate det_dropoff_marker invisible
	}

	trigger invisible
	{
		setstate det_dropoff_marker invisible
		wait 100
	}

	trigger visible
	{
		setstate det_dropoff_marker default
		wait 100
	}
}

tug_wall
{
	spawn
	{
		wait 200
		setstate tug_wall default
	}

	trigger visible
	{
		setstate dyna_lever default
		wait 100
	}

	death
	{
		trigger det_dropoff_marker invisible
		trigger det_bat_dropoff invisible
		wait 2000
		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Allies have breached the Vault!"
		// *---------------------------------------------------------------------------------*
	}
}

dyna_lever
{
	spawn
	{
		wait 200
		setstate dyna_lever invisible
	}

	trigger visible
	{
		setstate dyna_lever default
		wait 100
	}

	death
	{
		trigger det_dropoff_marker invisible
		trigger det_bat_dropoff invisible
		wait 1000
		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Allies has breached the Vault!"
		// *---------------------------------------------------------------------------------*
	}
}

dyna_lever_nouse
{
	spawn
	{
		wait 200
		setstate dyna_lever_nouse default
	}

	trigger invisible
	{
		setstate dyna_lever_nouse invisible
		wait 100
	}

	trigger visible
	{
		setstate dyna_lever_nouse default
		wait 100
	}
}



truckbox1
{
	spawn
	{
		wait 50
		setstate truckbox1 invisible
		accum 1 set 0
	}

	trigger visible
	{
		setstate truckbox1 default
		accum 1 abort_if_not_equal 0

		accum 1 set 1

		setstate det_bat_flag invisible
	}

	trigger invisible
	{
		setstate truckbox1 invisible
	}
}


truckboxtrans1
{
	trigger visible
	{
		setstate truckboxtrans1 default
	}

	trigger invisible
	{
		setstate truckboxtrans1 invisible
	}
}

radarbox1
{
	spawn
	{
	}

	trigger stolen
	{
		trigger det_bat_flag invisible
		trigger det_bat_marker invisible
		trigger det_bat_dropoff visible
		trigger det_dropoff_marker visible

		wait 1000

		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Allies has taken the Detonator Battery!"

		//wm_teamvoiceannounce 0 "axis_hq_objective_taken"
		//wm_teamvoiceannounce 1 "allies_hq_objective_taken"
		// *---------------------------------------------------------------------------------*
	}

	trigger returned
	{
		trigger det_bat_flag visible
		trigger det_bat_marker visible

		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Axis has secured the Detonator Battery!"

		wm_teamvoiceannounce 0 "axis_hq_objective_secured"
		wm_teamvoiceannounce 1 "allies_hq_objective_secured"
		// *---------------------------------------------------------------------------------*

		alertentity town_spawn
		alertentity town_spawn_allies
		alertentity town_spawn_axis
		setautospawn "Town Spawn" 0
		setautospawn "Truck Spawn" 1
	}

	trigger captured
	{
		trigger truckbox1 visible
		trigger truckboxtrans1 invisible
		wait 1000

		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Allies have armed the Train Dynamite Detonator!"

		wm_teamvoiceannounce 0 "axis_hq_objective_captured"
		wm_teamvoiceannounce 1 "allies_hq_objective_captured"
		// *---------------------------------------------------------------------------------*

		trigger town_spawn_axis kill
		trigger town_spawn_allies2 visible
		alertentity town_spawn
		setautospawn "Town Spawn" 1
		setautospawn "Gun Spawn" 0

		// *----------- Delay the trigger, so it cant be used directly after cap ------------*
		wait 1000
		wm_announce	"The detonator will charge in 15 seconds!"
		playsound sound/weapons/dynamite/dynamite_timer.wav
		wait 5000
		wm_announce	"The detonator will charge in 10 seconds!"
		playsound sound/weapons/dynamite/dynamite_timer.wav
		wait 5000
		wm_announce	"The detonator will charge in 5 seconds!"
		playsound sound/weapons/dynamite/dynamite_timer.wav
		wait 5000
		wm_announce	"The detonator is now charged!"
		trigger dyna_lever_nouse invisible
		trigger dyna_lever visible

		wm_objective_status 3 1 1
		wm_objective_status 3 0 2

	}
}

det_bat_dropoff
{
	spawn
	{
		wait 200
		setstate det_bat_dropoff invisible
	}

	death
	{
		trigger radarbox1 captured
	}

	trigger visible
	{
		setstate det_bat_dropoff default
	}

	trigger invisible
	{
		setstate det_bat_dropoff invisible
	}
}

// ============================================
// Destructable Stuff
// ============================================

gun // The Big Gun at the end.
{
	spawn
	{
		wait 50
		constructible_class	3
	}

	death
	{
		trigger game_manager gun_boom
	}
}

// ================================================
// ============ NEUTRAL COMMAND POST ==============
// ================================================

allied_compost_built
{
	spawn
	{
		wait 400
		trigger allied_compost_built setup

		constructible_class 2
	}

	trigger setup
	{
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0
	}

	buildstart final
	{
		setstate allied_compost_built_model underconstruction
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible
	}

	built final
	{
		setstate allied_compost_built_model default
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible

		trigger allied_compost_built_model enable_allied_features

		enablespeaker allies_compost_sound
	}

	decayed final
	{
		setstate allied_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default
	}

	death
	{
		setstate allied_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default

		trigger allied_compost_built_model disable_allied_features

		disablespeaker allies_compost_sound
	}
}

allied_compost_built_model
{
	spawn
	{
		wait 400
		setstate allied_compost_built_model invisible
	}

	trigger enable_allied_features
	{
		setchargetimefactor 1 soldier 0.75
		setchargetimefactor 1 lieutenant 0.75
		setchargetimefactor 1 medic 0.75
		setchargetimefactor 1 engineer 0.75
		setchargetimefactor 1 covertops 0.75
		sethqstatus 1 1

		wm_announce	"Allied Command Post constructed. Charge speed increased!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed_allies"

		wm_teamvoiceannounce 1 "allies_hq_compost_constructed"

		wm_removeteamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 3 0 2
		wm_objective_status 3 1 1
	}

	trigger disable_allied_features
	{
		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1
		sethqstatus 1 0

		wm_announce	"Axis team has destroyed the Allied Command Post!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "axis_hq_compost_construct"

		wm_teamvoiceannounce 1 "allies_hq_compost_damaged"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 3 0 0
		wm_objective_status 3 1 0
	}
}

axis_compost_built
{
	spawn
	{
		wait 400
		trigger axis_compost_built setup

		constructible_class 2
	}

	trigger setup
	{
		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0
	}

	buildstart final
	{
		setstate axis_compost_built_model underconstruction
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible
	}

	built final
	{
		setstate axis_compost_built_model default
		setstate neutral_compost_closed_clip invisible
		setstate neutral_compost_closed_model invisible

		trigger axis_compost_built_model enable_axis_features

		enablespeaker axis_compost_sound
	}

	decayed final
	{
		setstate axis_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default
	}

	death
	{
		setstate axis_compost_built_model invisible
		setstate neutral_compost_closed_clip default
		setstate neutral_compost_closed_model default

		trigger axis_compost_built_model disable_axis_features

		disablespeaker axis_compost_sound
	}
}

axis_compost_built_model
{
	spawn
	{
		wait 400
		setstate axis_compost_built_model invisible
	}

	trigger enable_axis_features
	{
		setchargetimefactor 0 soldier 0.75
		setchargetimefactor 0 lieutenant 0.75
		setchargetimefactor 0 medic 0.75
		setchargetimefactor 0 engineer 0.75
		setchargetimefactor 0 covertops 0.75
		sethqstatus 0 1

		wm_announce	"Axis Command Post constructed. Charge speed increased!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed"

		wm_teamvoiceannounce 1 "allies_hq_compost_constructed_axis"

		wm_removeteamvoiceannounce 0 "axis_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 3 0 1
		wm_objective_status 3 1 2
	}

	trigger disable_axis_features
	{
		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1
		sethqstatus 0 0

		wm_announce	"Allied team has destroyed the Axis Command Post!"

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"

		wm_teamvoiceannounce 0 "axis_hq_compost_damaged"

		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*

		wm_objective_status 3 0 0
		wm_objective_status 3 1 0
	}
}

// ============================================
// Key Code Documents
// ============================================

secretdocs_toi
{
	spawn
	{
		wait 200
		setstate secretdocs_toi default
	}

	trigger invisible
	{
		setstate secretdocs_toi invisible
		wait 100
	}

	trigger visible
	{
		setstate secretdocs_toi default
		wait 100
	}
}

secretdocs_marker
{
	spawn
	{
		wait 200
		setstate secretdocs_marker default
	}

	trigger invisible
	{
		setstate secretdocs_marker invisible
		wait 100
	}

	trigger visible
	{
		setstate secretdocs_marker default
		wait 100
	}
}

keycode_marker
{
	spawn
	{
		wait 200
		setstate keycode_marker invisible
	}

	trigger invisible
	{
		setstate keycode_marker invisible
		wait 100
	}

	trigger visible
	{
		setstate keycode_marker default
		wait 100
	}
}

keycode_toi
{
	spawn
	{
		wait 200
		setstate keycode_toi invisible
	}

	trigger invisible
	{
		setstate keycode_toi invisible
		wait 100
	}

	trigger visible
	{
		setstate keycode_toi default
		wait 100
	}
}


keycode_dropoff
{
	spawn
	{
		wait 200
		setstate keycode_dropoff invisible
	}

	death
	{
		trigger secretdocs captured
	}

	trigger visible
	{
		setstate keycode_dropoff default
	}

	trigger invisible
	{
		setstate keycode_dropoff invisible
	}
}

keycode_door_open
{
	spawn
	{
		wait 200
		setstate keycode_door_open invisible
	}

	trigger visible
	{
		setstate keycode_door_open default
		wm_announce	"The Key Code Door is now Unlocked!"
		wait 1000
		wm_announce	"The Big Gun is now unsecured and can be destroyed!"
	}

	trigger invisible
	{
		setstate keycode_door_open invisible
	}
}

keycode_door_locked
{
	spawn
	{
		wait 200
		setstate keycode_door_locked invisible
		remove
	}

	trigger visible
	{
		setstate keycode_door_locked invisible
	}

	trigger invisible
	{
		setstate keycode_door_locked invisible
	}
}

secretdocs
{
	spawn
	{
	}

	trigger stolen
	{
		trigger secretdocs_toi invisible
		trigger secretdocs_marker invisible
		trigger keycode_toi visible
		trigger keycode_dropoff visible
		trigger keycode_marker visible

		wait 1000

		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Allies has taken the Key-Code Documents!"

		wait 1000
		wm_announce	"The Key-Code Lock in the Farmhouse is about to be unlocked!"
		// *---------------------------------------------------------------------------------*
	}

	trigger returned
	{
		trigger secretdocs_toi visible
		trigger secretdocs_marker visible

		// *----------------------------------- vo ------------------------------------------*
		wm_announce	"Axis has secured the Key-Code Documents!"

		wm_teamvoiceannounce 0 "axis_hq_objective_secured"
		wm_teamvoiceannounce 1 "allies_hq_objective_secured"
		// *---------------------------------------------------------------------------------*
	}

	trigger captured
	{
		wait 1000
		trigger keycode_door_locked invisible
		trigger keycode_door_open visible

		wm_objective_status 4 1 1
		wm_objective_status 4 0 2

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "railgun_axis_controls_defend"
		wm_addteamvoiceannounce 1 "railgun_allies_controls_destroy"
		wm_teamvoiceannounce 0 "railgun_axis_controls_defend"
		wm_teamvoiceannounce 1 "railgun_allies_controls_destroy"
		// *---------------------------------------------------------------------------------*
	}
}

//==============================================
//======        High GuardTower         =======
//==============================================
town_barb // From fliegerhorst, now Guardtower
{
	spawn
	{
		wait 400
		trigger town_barb setup

		constructible_class 2
	}

	trigger setup
	{
		setstate town_barb_materials default
		setstate town_barb_materials_clip default
		setstate town_barb_flag default

		setstate town_barb invisible
		setstate hill_shoot_mg invisible

	}

	buildstart final
	{
		setstate town_barb_materials default
		setstate town_barb_materials_clip default
		setstate town_barb_flag default


		setstate town_barb underconstruction
		setstate hill_shoot_mg underconstruction
	}

	built final
	{
		setstate town_barb_materials invisible
		setstate town_barb_materials_clip invisible
		setstate town_barb_flag invisible


		setstate town_barb default
		setstate hill_shoot_mg invisible

	}

	decayed final
	{
		setstate town_barb_materials default
		setstate town_barb_materials_clip default
		setstate town_barb_flag default


		setstate town_barb invisible
		setstate hill_shoot_mg invisible

	}

	death
	{
		setstate town_barb_materials default
		setstate town_barb_materials_clip default
		setstate town_barb_flag default


		setstate town_barb invisible
		setstate hill_shoot_mg invisible
		repairmg42 hill_shoot_mg

		wm_announce "The high Guardtower have been destroyed!"

	}

	trigger remove
	{
		setstate town_barb_toi invisible
		setstate town_barb_materials invisible
		setstate town_barb_materials_clip invisible
		setstate town_barb_flag invisible
		setstate town_barb invisible
		setstate hill_shoot_mg invisible

		remove
	}
}

//==============================================
//======        Schutzschild         =======
//==============================================

town_shoot // Schutzschild
{
	spawn
	{
		wait 400
		trigger town_shoot setup

		constructible_class 2
	}

	trigger setup
	{
		setstate town_shoot_materials default
		setstate town_shoot_materials_clip default
		setstate town_shoot_flag default

		setstate town_shoot invisible
		setstate town_shoot_mg invisible

	}

	buildstart final
	{
		setstate town_shoot_materials default
		setstate town_shoot_materials_clip default
		setstate town_shoot_flag default


		setstate town_shoot underconstruction
		setstate town_shoot_mg underconstruction
	}

	built final
	{
		setstate town_shoot_materials invisible
		setstate town_shoot_materials_clip invisible
		setstate town_shoot_flag invisible


		setstate town_shoot default
		setstate town_shoot_mg default

		wm_announce "The Schutzschild have been built."

	}

	decayed final
	{
		setstate town_shoot_materials default
		setstate town_shoot_materials_clip default
		setstate town_shoot_flag default


		setstate town_shoot invisible
		setstate town_shoot_mg invisible
	}

	death
	{
		setstate town_shoot_materials default
		setstate town_shoot_materials_clip default
		setstate town_shoot_flag default


		setstate town_shoot invisible
		setstate town_shoot_mg invisible
		repairmg42 town_shoot_mg

		wm_announce "The Schutzschild have been destroyed!"

	}

	trigger remove
	{
		setstate town_shoot_toi invisible
		setstate town_shoot_materials invisible
		setstate town_shoot_materials_clip invisible
		setstate town_shoot_flag invisible
		setstate town_shoot invisible
		trigger town_shoot_mg invisible

		remove
	}
}

//==============================================
//======           Big Gun MG            =======
//==============================================

gun_build // MG nest at the Big Gun
{
	spawn
	{
		wait 400
		trigger gun_build setup

		constructible_class 2
	}

	trigger setup
	{
		setstate gun_build_materials default
		setstate gun_build_materials_clip default
		setstate gun_build_flag default

		setstate gun_build invisible
		setstate gun_build_mg invisible

	}

	buildstart final
	{
		setstate gun_build_materials default
		setstate gun_build_materials_clip default
		setstate gun_build_flag default

		setstate gun_build underconstruction
		setstate gun_build_mg underconstruction
	}

	built final
	{
		setstate gun_build_materials invisible
		setstate gun_build_materials_clip invisible
		setstate gun_build_flag invisible

		setstate gun_build default
		setstate gun_build_mg invisible

	}

	decayed final
	{
		setstate gun_build_materials default
		setstate gun_build_materials_clip default
		setstate gun_build_flag default

		setstate gun_build invisible
		trigger gun_build_mg invisible
	}

	death
	{
		setstate gun_build_materials default
		setstate gun_build_materials_clip default
		setstate gun_build_flag default

		setstate gun_build invisible
		setstate gun_build_mg invisible
		repairmg42 gun_build_mg


		wm_announce "The Big Gun MG have been destroyed!"

	}

	trigger remove
	{
		setstate gun_build_toi invisible
		setstate gun_build_materials invisible
		setstate gun_build_materials_clip invisible
		setstate gun_build_flag invisible
		setstate gun_build invisible
		setstate gun_build_mg invisible

		remove
	}
}
